package com.roin.learn.springsecurity.model;

import com.roin.learn.springsecurity.entity.SysAdmin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 *SpringSecurity需要的鉴权用户信息
 * 这里不直接使用SysAdmin类是为了将与数据库实体进行解耦
 */
public class AdminDetails  implements UserDetails {

    private SysAdmin admin;
    private List<GrantedAuthority> authorities;

    public AdminDetails(SysAdmin admin, List<GrantedAuthority> authorities) {
        this.admin = admin;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return admin.getPassword();
    }

    @Override
    public String getUsername() {
        return admin.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return admin.getAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return admin.getAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return admin.getCredentialsNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return admin.getEnabled();
    }
}
